package com.lzm.repository;

import com.lzm.domain.Seckill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

public interface SeckillRepository extends JpaRepository<Seckill, Long> {

    /**
     * 减库存
     */
    @Query(value = "UPDATE seckill\n" +
            "SET number = number-1\n" +
            "WHERE seckill_id=?1\n" +
            "AND start_time <= ?2\n" +
            "AND end_time >= ?2\n" +
            "AND number > 0",
            nativeQuery = true)
    int reduceNumber(Long seckillId, Date killTime);

}
